package com.lz.football.module.guide.view
{
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.BagEvent;
	import com.liangzhong.events.GuideEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.bag.BagView;
	import com.lz.football.module.guide.Guide;
	import com.lz.football.module.main.view.MainView;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	/**
	 * 球星入阵容 
	 * @author lake
	 * 
	 */	
	public class UsePlayerCardGuideView extends Guide
	{
		public function UsePlayerCardGuideView()
		{
			super();
		}
		/**
		 *初始化 
		 */		
		override protected function initView():void
		{
			super.initView();
			//限制区域
			var rectPoint :Point = MainView.bagBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,MainView.bagBtn.width,MainView.bagBtn.height);
			step();
			//指向仓库图标按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width/2,curClickRect.y);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,0);
			sceneBtn = MainView.bagBtn;
			arrowAngle = 0;
			//排序道具 
			AppData.getInstance().bagDataManager.playerCardFirst();
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			//disable
			MainView.playerBtn.mouseEnabled = false;
			MainView.techBtn.mouseEnabled = false;
		}
		/**
		 *界面显示
		 * @param e
		 * 
		 */		
		private function onLoadResComplete2(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			//限制区域
			var rectPoint :Point = BagView.firstItem.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,BagView.firstItem.width,BagView.firstItem.height);
			step();
			//指向第一格子
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn = BagView.firstItem;
			arrowAngle = -90;
			//事件
			AppEventDispatcher.getInstance().addEventListener("Bag_Guide_Select_Item",selectItem);
		}
		/**
		 *选中物品 
		 * @param e
		 * 
		 */		
		private function selectItem(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener("Bag_Guide_Select_Item",selectItem);
			//限制区域
			var rectPoint :Point = BagView.useBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,BagView.useBtn.width,BagView.useBtn.height);
			step();
			//指向使用
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  BagView.useBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(BagEvent.USE_ITEM,useItem1);
		}
		/**
		 *使用
		 * 
		 */		
		private function useItem(e:Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(BagEvent.USE_ITEM,useItem);
			//限制区域
			var rectPoint :Point = BagView.firstItem.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,BagView.firstItem.width,BagView.firstItem.height);
			step();
			//指向第一格子
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn =  BagView.firstItem;
			arrowAngle = -90;
			//延后
			BagView.firstItem.mouseChildren = false;
			BagView.firstItem.mouseEnabled = false;
			TweenLite.delayedCall(.3,delaySort);
			//事件
			AppEventDispatcher.getInstance().addEventListener("Bag_Guide_Select_Item",selectItem1);
		}
		/**
		 *延后刷新 
		 */		
		private function delaySort():void
		{
			BagView.firstItem.mouseChildren = true;
			BagView.firstItem.mouseEnabled = true;
			//排序道具 
			AppData.getInstance().bagDataManager.playerCardFirst();
		}
		/**
		 *选中物品 
		 * @param e
		 * 
		 */		
		private function selectItem1(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener("Bag_Guide_Select_Item",selectItem1);
			//限制区域
			var rectPoint :Point = BagView.useBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,BagView.useBtn.width,BagView.useBtn.height);
			step();
			//指向使用
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  BagView.useBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(BagEvent.USE_ITEM,useItem1);
		}
		/**
		 *使用
		 * 
		 */		
		private function useItem1(e:Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(BagEvent.USE_ITEM,useItem1);
			//提交引导
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE,{step:4}));
			//限制区域
			var rectPoint :Point = BagView.CLoseBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,BagView.CLoseBtn.width,BagView.CLoseBtn.height);
			step();
			//指向关闭按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width + 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  BagView.CLoseBtn;
			arrowAngle = 90;
			//事件
			GlobalDef.GameStage.addEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
		}
		/**
		 *  关闭
		 * @param e
		 * 
		 */		
		private function onRemoveModuleHandler(e :Event):void
		{
			GlobalDef.GameStage.removeEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
			removeArrowMc();
			//第4步刷新
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE+"_refresh",{step:4}));
			//enable
			MainView.playerBtn.mouseEnabled = true;
			MainView.techBtn.mouseEnabled = true;
		}
		/**
		 *执行 
		 * 
		 */		
		override public function process():void
		{
			initView();
		}
		/**
		 *清理 
		 * 
		 */		
		override public function clear():void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			AppEventDispatcher.getInstance().removeEventListener("Bag_Guide_Select_Item",selectItem);
			AppEventDispatcher.getInstance().removeEventListener(BagEvent.USE_ITEM,useItem);
			AppEventDispatcher.getInstance().removeEventListener("Bag_Guide_Select_Item",selectItem1);
			AppEventDispatcher.getInstance().removeEventListener(BagEvent.USE_ITEM,useItem1);
			GlobalDef.GameStage.removeEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
			super.clear();
		}
	}
}